home *** CD-ROM | disk | FTP | other *** search
- /* MPEGSTAT - analyzing tool for MPEG-I video streams
- *
- * Technical University of Berlin, Germany, Dept. of Computer Science
- * Tom Pfeifer - Multimedia systems project - pfeifer@fokus.gmd.de
- *
- * Jens Brettin, Harald Masche, Alexander Schulze, Dirk Schubert
- *
- * ---------------------------
- *
- * Copyright (c) 1993 Technical University of Berlin, Germany
- * All rights reserved.
- *
- * ---------------------------
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notices and the following
- * two paragraphs appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA
- * or the Technical University of Berlin BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA or the Technical University of Berlin HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA and the Technical University of Berlin
- * SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
- * UNIVERSITY OF CALIFORNIA and the Technical University of Berlin HAVE NO
- * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
- * OR MODIFICATIONS.
- */
-
- /*
- * analyzing routines
- */
-
- #include <stdio.h>
- #include "video.h"
-
- #define max(a,b) (a>b?a:b)
- #define MAXPIC 2000
-
- static int bcounter; /* counter for bytes read */
- static char frame_seq[MAXPIC]; /* frame types as displayed */
-
- void byte_count(num)
- int num;
- {
- bcounter += num;
- }
-
- int print_bytes()
- {
- return bcounter;
- }
-
- int mvstat (int value, int mode)
- {
- static int max_horizontal_f = 0, max_vertical_f = 0;
- static int max_horizontal_b = 0, max_vertical_b = 0;
- static int ave_h_b = 0, ave_h_f = 0, ave_v_b = 0, ave_v_f = 0;
- static int qscale;
- static int count_h_b = 0, count_h_f = 0, count_v_b = 0, count_v_f = 0;
- int *ip;
-
- switch (mode) {
- case 0:
- ip = &max_horizontal_f;
- if(value != 0) {
- count_h_f++;
- ave_h_f += abs(value);
- }
- break;
- case 1:
- ip = &max_vertical_f;
- if(value != 0) {
- count_v_f++;
- ave_v_f += abs(value);
- }
- break;
- case 2:
- ip = &max_horizontal_b;
- if(value != 0) {
- count_h_b++;
- ave_h_b += abs(value);
- }
- break;
- case 3:
- ip = &max_vertical_b;
- if(value != 0) {
- count_v_b++;
- ave_v_b += abs(value);
- }
- break;
- case 4:
- ip = &qscale;
- break;
- case 5:
- return max_horizontal_f;
- case 6:
- return max_vertical_f;
- case 7:
- return max_horizontal_b;
- case 8:
- return max_vertical_b;
- case 9:
- return qscale;
- case 10 :
- if (count_h_f > 0)
- return( ave_h_f / count_h_f);
- else return 0;
- case 11 :
- if (count_v_f > 0)
- return( ave_v_f / count_v_f);
- else return 0;
- case 12 :
- if (count_h_b > 0)
- return( ave_h_b / count_h_b);
- else return 0;
- case 13 :
- if (count_v_b > 0)
- return( ave_v_b / count_v_b);
- else return 0;
-
- }
- *ip = max (*ip, abs (value));
- return 0;
- }
-
-
- /*
- * printtype prints the frame type during data parsing.
- */
-
- printtype(VidStream *vs)
- {
-
- static int first_time = 1;
-
- if(first_time) {
- printf("Frame sequence as found while parsing:\n");
- first_time = 0;
- }
-
- switch (vs->picture.code_type) {
- case B_TYPE:
- printf("B");
- break;
- case P_TYPE:
- printf("P");
- break;
- case I_TYPE:
- printf("I");
- break;
- default:
- printf("-unknown-");
- }
- fflush(stdout);
- }
-
- /*
- * display some frame attributes during output time
- */
-
- ShowOutputVal(VidStream *vs)
- {
- static i = 0;
-
- if(i >= MAXPIC -1)
- return;
-
- switch (vs->picture.code_type) {
- case B_TYPE:
- frame_seq[i++] = 'B';
- break;
- case P_TYPE:
- frame_seq[i++] = 'P';
- break;
- case I_TYPE:
- frame_seq[i++] = 'I';
- break;
- default:
- printf("-unknown-");
- }
-
- frame_seq[i] = '\0';
-
- }
-
-
- Search4Pattern()
- {
- char tmpbuf[MAXPIC];
-
- char *s;
- int i = 0;
- s = frame_seq;
-
- printf("\nSearching for constant frame type sequence...");
- while(*s != 'I' )
- ++s ;
-
- tmpbuf[i++] = *s++;
-
- while ((tmpbuf[i++] = *s) != 'I' )
- ++s;
- tmpbuf[i - 1] = '\0';
-
- if(!memcmp(s, tmpbuf,--i))
- if(!memcmp(s + i, tmpbuf, i))
- if(!memcmp(s + 2*i, tmpbuf, i)) {
- printf("pattern detected: %s\n\n", tmpbuf);
- return(1);
- }
- printf("No constant frame type pattern found.\n");
- return(0);
- }
-
- ShowFrameSeq()
- {
- printf("\n\nFrame sequence as to be displayed: \n%s\n\n", frame_seq);
-
- Search4Pattern();
- }
-